package com.yuzhitong.shapi.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.yuzhitong.shapi.R;

import a.a.a.MyApplication;

/**
 * Created by Brsya
 * CreateDate: 2022/4/19  16:30
 * Description:
 * 隐私协议弹框
 */
public class HintDialog extends CenterDialog implements View.OnClickListener {
    private Context context;
    private View rootView;
    private TextView textCancel;
    private TextView textConfirm;


    private OnClickBtnListener onClickBtnListener;
    private TextView tvHintDialogTitle;
    private TextView tvHintDialogText;

    public HintDialog(Context context) {
        super(context);
        this.context = context;

        setContentView(rootView = LayoutInflater.from(context).inflate(R.layout.dialog_hint, null, false));

        initView();
    }

    private void initView() {
        setKeyListener(false);

        tvHintDialogTitle = rootView.findViewById(R.id.tv_hint_dialog_title);
        tvHintDialogText = rootView.findViewById(R.id.tv_hint_dialog_text);
        textCancel = (TextView) rootView.findViewById(R.id.text_cancel);
        textConfirm = (TextView) rootView.findViewById(R.id.text_confirm);

        textCancel.setOnClickListener(this);
        textConfirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.text_cancel) {
            dismiss();
            if (onClickBtnListener != null) {
                onClickBtnListener.onDismiss();
            }
        } else if (id == R.id.text_confirm) {
            MyApplication.agreeIsTrue();
            dismiss();
            if (onClickBtnListener != null) {
                onClickBtnListener.onConfirm();
            }
        }
    }

    public HintDialog setTitle(CharSequence title){
        tvHintDialogTitle.setText(title);
        return this;
    }

    public HintDialog setText(CharSequence title){
        tvHintDialogText.setText(title);
        return this;
    }

    public HintDialog setSubmitText(CharSequence title){
        textConfirm.setText(title);
        return this;
    }

    public HintDialog setCancelText(CharSequence title){
        textCancel.setText(title);
        return this;
    }


    public HintDialog setOnClickBtnListener(OnClickBtnListener onClickBtnListener) {
        this.onClickBtnListener = onClickBtnListener;
        return this;
    }

    public interface OnClickBtnListener {
        void onDismiss();

        void onConfirm();
    }
}
